﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace Freshome.m
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(string.Format("发生了未处理的异常：{0}\n{1}", e.Exception.GetType().ToString(), e.Exception.Message));
        }
    }
    public class SingleInstanceWrapper : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
    {
        public SingleInstanceWrapper()
        {
            // Enable single-instance mode.
            this.IsSingleInstance = true;
        }
        // Create the WPF application class.
        private App theApp;
        protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
        {
            theApp = new App();
            theApp.InitializeComponent();
            theApp.Run();
            return false;
        }
        // Direct multiple instances.
        protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs e)
        {
            Window mw = theApp.MainWindow;
            if (mw.WindowState == WindowState.Minimized)
            {
                mw.WindowState = WindowState.Normal;
            }
            mw.Activate();
        }
    }
    public class Startup
    {
        [STAThread]
        public static void Main(string[] args)
        {
            SingleInstanceWrapper wrapper = new SingleInstanceWrapper();
            wrapper.Run(args);
        }
    }
}
